<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;


return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('e_s_units', function (Blueprint $table) {
            $table->id();
            $table->string('name')->nullable(true)->comment('名称');
            $table->string('location')->nullable(true)->comment('位置');
            $table->string('capacity')->nullable(true)->comment('额定电量');
            $table->string('current_power')->nullable(true)->comment('当前电量');
            $table->json('info')->nullable(true)->comment('其他信息(json)');
            $table->string('remarks')->nullable(true)->comment('备注');
            $table->unsignedBigInteger('e_s_station_id')->comment('所属储能站id');
            $table->timestamps();
        });
        Schema::create('e_s_clusters', function (Blueprint $table) {
            $table->id();
            $table->string('name')->nullable(true)->comment('名称');
            $table->string('location')->nullable(true)->comment('位置');
            $table->decimal('capacity', 10, 2)->nullable(true)->comment('额定电量');
            $table->decimal('current_power', 10, 2)->nullable(true)->comment('当前电量');
            $table->json('info')->nullable(true)->comment('其他信息(json)');
            $table->string('remarks')->nullable(true)->comment('备注');
            $table->unsignedBigInteger('e_s_unit_id')->comment('所属储能单元id');
            $table->timestamps();
        });
        Schema::create('e_s_cluster_charge_logs', function (Blueprint $table) {
            $table->id();
            $table->timestamp('begin_at')->nullable(true)->comment('起始时间');
            $table->timestamp('end_at')->nullable(true)->comment('结束时间');
            $table->decimal('power', 10, 2)->nullable(true)->comment('电量');
            $table->enum('state', ['charge', 'discharge'])->default('discharge')->comment('状态');
            $table->string('remarks')->nullable(true)->comment('备注');
            $table->unsignedBigInteger('e_s_cluster_id')->comment('所属储能簇id');
            $table->timestamps();
        });
        Schema::create('e_s_batteries', function (Blueprint $table) {
            $table->id();
            $table->string('name')->comment('名称');
            $table->string('brand')->nullable(true)->comment('电池品牌');
            $table->string('begin_at')->nullable(true)->comment('起始时间');
            $table->string('production_date')->nullable(true)->comment('出厂日期');
            $table->string('type')->nullable(true)->comment('类型:锂电');
            $table->string('manufacturer')->nullable(true)->comment('制造商');
            $table->decimal('capacity', 10, 2)->nullable(true)->comment('容量');
            $table->string('chip')->nullable(true)->comment('电池芯片');
            $table->string('use_type')->nullable(true)->comment('梯次利用');
            $table->string('form')->nullable(true)->comment('组成方式');
            $table->string('cooling')->nullable(true)->comment('冷却方式');
            $table->json('info')->nullable(true)->comment('其他信息(json)');
            $table->string('remarks')->nullable(true)->comment('备注');
            $table->unsignedBigInteger('e_s_cluster_id')->comment('所属储能簇id');
            $table->timestamps();
        });
        Schema::create('e_s_battery_cells', function (Blueprint $table) {
            $table->id();
            $table->string('name')->nullable(true)->comment('名称');
            $table->json('info')->nullable(true)->comment('其他信息(json)');
            $table->string('remarks')->nullable(true)->comment('备注');
            $table->unsignedBigInteger('e_s_battery_id')->comment('所属电池包id');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('e_s_units');
        Schema::dropIfExists('e_s_clusters');
        Schema::dropIfExists('e_s_cluster_charge_logs');
        Schema::dropIfExists('e_s_batteries');
        Schema::dropIfExists('e_s_battery_cells');
    }
};
